package com.dyh.quickdemozwei.shiyanchang.pipeLine;



import java.util.Map;
import java.util.function.Function;

public class PipeLineBaseExecutor extends AbstarctPipeExecutor {
    Map<String, Function> springBeanMap;
    

    public void setSpringBeanMap(Map<String, Function> springBeanMap) {
        this.springBeanMap = springBeanMap;
    }

    @Override
    public Object execute(String cmd) {
        String[] arr = cmd.split("\\|");
        String start = arr[0];
        Object obj = start;

        for (int i=1;i<arr.length;i++){
            String fucName = arr[i];
            Function function = routeFuncntion(fucName);
            if (function==null)
                throw new RuntimeException("function with name"+ fucName+"not found");
            obj = function.apply(obj);
        }
        return obj;
    }

    private Function routeFuncntion(String str){
        Function result = null;
        result = commonFunctions.get(str);
        if (result!=null)
            return result;

        result = springBeanMap.get(str);
        if (result!=null)
            return result;

        return null;
    }



}
